package com.hrbxlh.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.hrbxlh.actionImpl.*;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.hrbxlh.util.ConfigFileUtil;
import com.hrbxlh.util.FileUpload;
import com.hrbxlh.util.SessionValues;

/**
 * -------------------------------------------------------
 * Copyright (c) 2017, 鑫联华信息科技股份有限公司
 * All rights reserved.
 * FileName：HomeworkTestAction.java
 * Description：作业和试验action类
 * History：
 * Date           Author               Desc
 * 2017.4.5		  xzx                 建立
 * 2017.09.19	  xzx				修改3.0（前面都有注释3.0）
 * -------------------------------------------------------
 */

@Controller
public class HomeworkTestAction {

	@Autowired
	@Qualifier("homeworkTestActionImpl")
	private HomeworkTestActionImpl homeworkTestActionImpl;

	@Autowired
	@Qualifier("courseActionImpl")
	private CourseActionImpl courseActionImpl;

	@Autowired
	@Qualifier("chapterActionImpl")
	private ChapterActionImpl chapterActionImpl;

	@Autowired
	@Qualifier("classActionImpl")
	private ClassActionImpl classActionImpl;

	@Autowired
	@Qualifier("sourceActionImpl")
	private SourceActionImpl sourceActionImpl;

	/**作业管理  进页面
	 * @description 进页面，带登录人教的课程信息（id，名字） 带教师教的班级信息（班级id，班级名称）
	列表：课程名，作业名称，上课时间，交作业进度，（交作业人数，全部人数），查看按钮      带分页
	 * @param request
	 * @param response
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/skipHomeworkMana", method = RequestMethod.POST)
	public void skipHomeworkMana(String jsonStr,HttpServletRequest request, HttpServletResponse response)   {

		//转换json格式工具
		ObjectMapper mapper = new ObjectMapper();
		//存放结果值
		Map<String,Object> resultMap = new HashMap<String,Object>();
		//日志信息
		Logger logger = Logger.getLogger(HomeworkTestAction.class.getName());
		try {
			Map<String,Object> preParamMap = new HashMap<String, Object>();
			//获取参数值
			if(jsonStr != null){
				preParamMap = mapper.readValue(jsonStr, resultMap.getClass());
			}
			//获取登录人id
			SessionValues session = new SessionValues();
			Map<String, Object> sessionValues = session.getSessionValues(new String[]{"stuorteaId"}, request, "userMsg");
			preParamMap.put("stuorteaId", sessionValues.get("stuorteaId"));
			//获取教师教的课程id以及名称
			preParamMap.put("searchNoEnd", 0);
			List<Map<String, Object>> courseList = courseActionImpl.getTeaTeachCourse(preParamMap);
			resultMap.put("courseList", courseList);
			//获取教师的所有班级（从中间表里查）
			List<Map<String, Object>> classList = homeworkTestActionImpl.getTeaTeachClass(preParamMap);
			resultMap.put("classList", classList);
			//获取课堂班级课程作业情况
			Map<String, Object> homeworkListMap = homeworkTestActionImpl.getTeaHomeworkList(preParamMap);
			if(homeworkListMap != null){
				resultMap.put("homeworkList", homeworkListMap.get("homeworkList"));
				resultMap.put("totalPage", homeworkListMap.get("totalPage"));
				resultMap.put("pageNow", homeworkListMap.get("pageNow"));
			}
			//返回条件
			resultMap.put("pageSize", preParamMap.get("pageSize"));
			if(preParamMap.get("courseId") != null){
				resultMap.put("courseId", preParamMap.get("courseId"));
			}
			if(preParamMap.get("classId") != null){
				resultMap.put("classId", preParamMap.get("classId"));
			}
			resultMap.put("result", "success");
		} catch (Exception e) {
			resultMap.put("result", "fail");
			e.printStackTrace();
			logger.error("跳转作业管理页面出现异常skipHomeworkMana", e);
		} finally {
			try {
				courseActionImpl.responseStream(response, mapper.writeValueAsString(resultMap));
			} catch (JsonProcessingException e) {
				e.printStackTrace();
			}
		}
	}

	/**实验管理  进页面
	 * @description 进页面，带登录人教的课程信息（id，名字） 带教师教的班级信息（班级id，班级名称）
	列表：课程名，作业名称，上课时间，交实验进度，（交作业人数，全部人数），查看按钮      带分页
	 * @param request
	 * @param response
	 * @return  跳转到实验管理页面（导航） 以及条件查询

	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/skipTestMana", method = RequestMethod.POST)
	public void skipTestMana(String jsonStr,HttpServletRequest request, HttpServletResponse response)   {

		//转换json格式工具
		ObjectMapper mapper = new ObjectMapper();
		//存放结果值
		Map<String,Object> resultMap = new HashMap<String,Object>();
		//日志信息
		Logger logger = Logger.getLogger(HomeworkTestAction.class.getName());
		try {
			Map<String,Object> preParamMap = new HashMap<String, Object>();
			//获取参数值
			if(jsonStr != null){
				preParamMap = mapper.readValue(jsonStr, resultMap.getClass());
			}
			//获取登录人id
			SessionValues session = new SessionValues();
			Map<String, Object> sessionValues = session.getSessionValues(new String[]{"stuorteaId"}, request, "userMsg");
			preParamMap.put("stuorteaId", sessionValues.get("stuorteaId"));
			//获取教师教的课程id以及名称
			preParamMap.put("searchNoEnd", 0);
			List<Map<String, Object>> courseList = courseActionImpl.getTeaTeachCourse(preParamMap);
			resultMap.put("courseList", courseList);
			//获取教师的所有班级（从中间表里查）
			List<Map<String, Object>> classList = homeworkTestActionImpl.getTeaTeachClass(preParamMap);
			resultMap.put("classList", classList);
			//获取课堂班级课程实验情况
			Map<String, Object> testListMap = homeworkTestActionImpl.getTeaTestList(preParamMap);
			if(testListMap != null){
				resultMap.put("testList", testListMap.get("testList"));
				resultMap.put("totalPage", testListMap.get("totalPage"));
				resultMap.put("pageNow", testListMap.get("pageNow"));
			}
			//返回条件
			resultMap.put("pageSize", preParamMap.get("pageSize"));
			if(preParamMap.get("courseId") != null){
				resultMap.put("courseId", preParamMap.get("courseId"));
			}
			if(preParamMap.get("classId") != null){
				resultMap.put("classId", preParamMap.get("classId"));
			}
			resultMap.put("result", "success");
		} catch (Exception e) {
			resultMap.put("result", "fail");
			e.printStackTrace();
			logger.error("跳转实验管理页面出现异常skipTestMana", e);
		} finally {
			try {
				courseActionImpl.responseStream(response, mapper.writeValueAsString(resultMap));
			} catch (JsonProcessingException e) {
				e.printStackTrace();
			}
		}
	}

	/**作业管理  作业提交详情页面
	 * @description 作业提交详情页面,展示学生信息作业信息 分页
	 * @param request
	 * @param response
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/skipHomeworkDetail", method = RequestMethod.POST)
	public void skipHomeworkDetail(String jsonStr,HttpServletRequest request, HttpServletResponse response, HttpSession session)   {

		//转换json格式工具
		ObjectMapper mapper = new ObjectMapper();
		//存放结果值
		Map<String,Object> resultMap = new HashMap<String,Object>();
		//日志信息
		Logger logger = Logger.getLogger(HomeworkTestAction.class.getName());
		try {
			Map<String,Object> preParamMap = new HashMap<String, Object>();
			//获取参数值
			if(jsonStr != null){
				preParamMap = mapper.readValue(jsonStr, resultMap.getClass());
			}
			//班级名称
			Map<String ,Object> classMap = classActionImpl.getClassNameById(preParamMap);
			resultMap.put("classMsg", classMap);
			//章节名称
			Map<String, Object> chapterMap = chapterActionImpl.getCourseOneChapter(preParamMap);
			resultMap.put("chapterMsg", chapterMap);
			//列表信息
			Map<String, Object> homeworkListMap = homeworkTestActionImpl.getHomeWorkByClass(preParamMap);
			//查询当前登陆人设置的的等级信息
			//查询这个教师与这个课的成绩设置信息
			Map<String, Object> sorceMap = sourceActionImpl.getProWedith(session, preParamMap, request);
			if(homeworkListMap != null){
				resultMap.put("homeworkList", homeworkListMap.get("homeworkList"));
				resultMap.put("totalPage", homeworkListMap.get("totalPage"));
				resultMap.put("pageNow", homeworkListMap.get("pageNow"));
				resultMap.put("state", preParamMap.get("state"));
				resultMap.put("userName", preParamMap.get("userName"));
				resultMap.put("pageNow", homeworkListMap.get("pageNow"));
				resultMap.put("sorceMap", sorceMap.get("sorceMap"));

			}
			//返回条件
			resultMap.put("pageSize", preParamMap.get("pageSize"));
			//获取图片前缀   http://localhost:8081/SchoolManageSystem/images/pc/+文件名
			String[] keysArray = {"server_address", "project_name"};
			Map<String, Object> urlmap = ConfigFileUtil.getFileMessage("UtilFile.properties", keysArray);
			String imageUrl = (String)urlmap.get("server_address")+(String)urlmap.get("project_name")+"upload/images/";
			resultMap.put("imageUrl", imageUrl);
			//获取作业文件前缀
			String homeworkUrl = (String)urlmap.get("server_address")+(String)urlmap.get("project_name")+"upload/stuwork/";
			resultMap.put("homeworkUrl", homeworkUrl);
			//返回条件
			resultMap.put("courseId", preParamMap.get("courseId"));
			resultMap.put("chapterId", preParamMap.get("chapterId"));
			resultMap.put("chapterNum", preParamMap.get("chapterNum"));
			resultMap.put("classId", preParamMap.get("classId"));
			resultMap.putAll(sorceMap);
			//查询这个班与这个课的状态
			resultMap.put("classEndMark", homeworkTestActionImpl.getClassCourseEndMark(preParamMap).get("classEndMark"));
			resultMap.put("result", "success");
		} catch (Exception e) {
			resultMap.put("result", "fail");
			e.printStackTrace();
			logger.error("跳转作业管理内页页面出现异常skipHomeworkDetail", e);
		} finally {
			try {
				courseActionImpl.responseStream(response, mapper.writeValueAsString(resultMap));
			} catch (JsonProcessingException e) {
				e.printStackTrace();
			}
		}
	}

	/**实验管理 实验提交详情页面
	 * @description 实验提交详情页面,展示学生信息实验信息
	 * @param request
	 * @param response
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/skipTestDetail", method = RequestMethod.POST)
	public void skipTestDetail(String jsonStr,HttpServletRequest request, HttpServletResponse response, HttpSession session)   {

		//转换json格式工具
		ObjectMapper mapper = new ObjectMapper();
		//存放结果值
		Map<String,Object> resultMap = new HashMap<String,Object>();
		//日志信息
		Logger logger = Logger.getLogger(HomeworkTestAction.class.getName());
		try {
			Map<String,Object> preParamMap = new HashMap<String, Object>();
			//获取参数值
			if(jsonStr != null){
				preParamMap = mapper.readValue(jsonStr, resultMap.getClass());
			}
			//班级名称
			Map<String ,Object> classMap = classActionImpl.getClassNameById(preParamMap);
			resultMap.put("classMsg", classMap);
			//章节名称
			Map<String, Object> chapterMap = chapterActionImpl.getCourseOneChapter(preParamMap);
			resultMap.put("chapterMsg", chapterMap);
			//列表信息
			Map<String, Object> testListMap = homeworkTestActionImpl.getTestByClass(preParamMap);
			//查询当前登陆人设置的的等级信息
			Map<String, Object> sourceMap = sourceActionImpl.getProWedith(session,preParamMap,request);
			if(testListMap != null){
				resultMap.put("testList", testListMap.get("testList"));
				resultMap.put("totalPage", testListMap.get("totalPage"));
				resultMap.put("state", preParamMap.get("state"));
				resultMap.put("userName", preParamMap.get("userName"));
				resultMap.put("pageNow", testListMap.get("pageNow"));
				resultMap.put("sorceMap", sourceMap.get("sorceMap"));
			}
			//返回条件
			resultMap.put("pageSize", preParamMap.get("pageSize"));
			//获取图片前缀   http://localhost:8081/SchoolManageSystem/images/pc/+文件名
			String[] keysArray = {"server_address", "project_name"};
			Map<String, Object> urlmap = ConfigFileUtil.getFileMessage("UtilFile.properties", keysArray);
			String imageUrl = (String)urlmap.get("server_address")+(String)urlmap.get("project_name")+"upload/images/";
			resultMap.put("imageUrl", imageUrl);
			//获取实验文件前缀
			String testUrl = (String)urlmap.get("server_address")+(String)urlmap.get("project_name")+"upload/stuwork/";
			resultMap.put("testUrl", testUrl);
			//返回条件
			resultMap.put("courseId", preParamMap.get("courseId"));
			resultMap.put("chapterId", preParamMap.get("chapterId"));
			resultMap.put("chapterNum", preParamMap.get("chapterNum"));
			resultMap.put("classId", preParamMap.get("classId"));
			//查询这个教师与这个课的成绩设置信息
			Map<String, Object> sorceMap = sourceActionImpl.getProWedith(session, preParamMap, request);
			resultMap.putAll(sorceMap);
			//查询这个班与这个课的状态
			resultMap.put("classEndMark", homeworkTestActionImpl.getClassCourseEndMark(preParamMap).get("classEndMark"));
			resultMap.put("result", "success");
		} catch (Exception e) {
			resultMap.put("result", "fail");
			e.printStackTrace();
			logger.error("跳转实验管理内页页面出现异常skipTestDetail", e);
		} finally {
			try {
				courseActionImpl.responseStream(response, mapper.writeValueAsString(resultMap));
			} catch (JsonProcessingException e) {
				e.printStackTrace();
			}
		}
	}


	/**作业管理评价学生作业
	 * @description 点击某个学生的作业评价学生作业ajax请求
	 * @param request
	 * @param response
	 * @param jsonStr  章节id，学生号，taskSoruce（总成绩）
	 * @return  课表信息
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/getHomeworkDetailBySId", method = RequestMethod.POST)
	public void  getHomeworkDetailBySId (HttpServletResponse response, HttpServletRequest request, String jsonStr,HttpSession session)   {

		//转换json格式工具
		ObjectMapper mapper = new ObjectMapper();
		//存放结果值
		Map<String,Object> resultMap = new HashMap<String,Object>();
		//日志信息
		Logger logger = Logger.getLogger(HomeworkTestAction.class.getName());
		try {
			//获取参数值
			Map<String,Object> paramMap = mapper.readValue(jsonStr, resultMap.getClass());
			if(courseActionImpl.getMapSpecialMark(response, mapper, resultMap, paramMap)) return;
			//添加评价
			Map<String,Object> assessMark = homeworkTestActionImpl.getHomeworkDetailBySId(paramMap,request);
			String resultMark = ((Boolean)assessMark.get("result")) ? "success" : "fail";
			//返回标识
			resultMap.put("result", resultMark);
			resultMap.put("homework", assessMark.get("homework"));
			resultMap.put("failMsg",assessMark.get("failMsg"));
			courseActionImpl.responseStream(response, mapper.writeValueAsString(resultMap));
		} catch (Exception e) {
			resultMap.put("result", "fail");
			resultMap.put("failMsg","评价作业出现异常");
			e.printStackTrace();
			logger.error("评价作业出现异常assessHomework", e);
			try {
				courseActionImpl.responseStream(response, mapper.writeValueAsString(resultMap));
			} catch (JsonProcessingException e1) {
				e1.printStackTrace();
			}
		}
	}


	/**作业管理评价学生作业
	 * @description 评价学生作业
	 * @param request
	 * @param response
	 * @param jsonStr  课程id，章节id，学生号，taskSoruce（总成绩）
	 * @return  课表信息
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/assessHomework", method = RequestMethod.POST)
	public void  assessHomework (HttpServletResponse response, HttpServletRequest request, String jsonStr,HttpSession session)   {

		//转换json格式工具
		ObjectMapper mapper = new ObjectMapper();
		//存放结果值
		Map<String,Object> resultMap = new HashMap<String,Object>();
		//日志信息
		Logger logger = Logger.getLogger(HomeworkTestAction.class.getName());
		try {
			//获取参数值
			Map<String,Object> paramMap = mapper.readValue(jsonStr, resultMap.getClass());
//			if(courseActionImpl.getMapSpecialMark(response, mapper, resultMap, paramMap)) return;
			//添加评价
			Map<String,Object> assessMark = homeworkTestActionImpl.assessHomework(paramMap,request);
			String resultMark = ((Boolean)assessMark.get("result")) ? "success" : "fail";
			//添加该学生本门课程平时成绩
			if(resultMark.equals("success")){
				//添加该学生本门课程平时成绩
				homeworkTestActionImpl.addNormalNum(paramMap);
				//重新计算学生成绩信息的方法
				homeworkTestActionImpl.reCountDegree(paramMap,session,request);
				//返回标识
				resultMap.put("result", resultMark);
				resultMap.put("url",assessMark.get("url"));
				resultMap.put("failMsg", "");
			}else{
				//返回标识
				resultMap.put("result", "fail");
				resultMap.put("failMsg", assessMark.get("failMsg"));
			}
			courseActionImpl.responseStream(response, mapper.writeValueAsString(resultMap));
		} catch (Exception e) {
			resultMap.put("result", "fail");
			e.printStackTrace();
			logger.error("评价作业出现异常assessHomework", e);
			try {
				courseActionImpl.responseStream(response, mapper.writeValueAsString(resultMap));
			} catch (JsonProcessingException e1) {
				e1.printStackTrace();
			}
		}
	}

	/**实验管理评价学生实验
	 * @description 评价学生实验
	 * @param request
	 * @param response
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/assessTest", method = RequestMethod.POST)
	public void  assessTest (HttpServletResponse response, HttpServletRequest request, String jsonStr,HttpSession session)   {

		//转换json格式工具
		ObjectMapper mapper = new ObjectMapper();
		//存放结果值
		Map<String,Object> resultMap = new HashMap<String,Object>();
		//日志信息
		Logger logger = Logger.getLogger(HomeworkTestAction.class.getName());
		try {
			//获取参数值
			Map<String,Object> paramMap = mapper.readValue(jsonStr, resultMap.getClass());
//			if(courseActionImpl.getMapSpecialMark(response, mapper, resultMap, paramMap)) return;
			//添加评价
			Map<String, Object> assessMark = homeworkTestActionImpl.assessTest(paramMap,request);
			String resultMark = ((Boolean)assessMark.get("result")) ? "success" : "fail";
			if(resultMark.equals("success")){
				//添加该学生本门课程平时成绩
				homeworkTestActionImpl.addNormalNum(paramMap);
				//评价之后重新计算分数
				homeworkTestActionImpl.reCountDegree(paramMap,session,request);
				//返回标识
				resultMap.put("result", resultMark);
				resultMap.put("failMsg", "");
				resultMap.put("url",assessMark.get("url"));
			}else{
				//返回标识
				resultMap.put("result", resultMark);
				resultMap.put("failMsg", assessMark.get("failMsg"));
			}
			courseActionImpl.responseStream(response, mapper.writeValueAsString(resultMap));
		} catch (Exception e) {
			resultMap.put("result", "fail");
			resultMap.put("failMsg", "评价实验出现异常");
			e.printStackTrace();
			logger.error("评价实验出现异常assessTest", e);
			try {
				courseActionImpl.responseStream(response, mapper.writeValueAsString(resultMap));
			} catch (JsonProcessingException e1) {
				e1.printStackTrace();
			}
		}
	}

	/**实验管理评价学生实验
	 * @description 评价学生实验之动态获取成绩等级
	 * @param request
	 * @param response
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/getTestTaskFraction", method = RequestMethod.POST)
	public void  getTestTaskFraction (HttpServletResponse response, HttpServletRequest request, String jsonStr,HttpSession session)   {

		//转换json格式工具
		ObjectMapper mapper = new ObjectMapper();
		//存放结果值
		Map<String,Object> resultMap = new HashMap<String,Object>();
		//日志信息
		Logger logger = Logger.getLogger(HomeworkTestAction.class.getName());
		try {
			//获取参数值
			Map<String,Object> paramMap = mapper.readValue(jsonStr, resultMap.getClass());
			if(courseActionImpl.getMapSpecialMark(response, mapper, resultMap, paramMap)) return;
			//添加评价
			resultMap = homeworkTestActionImpl.getTestTaskFraction(paramMap,request);
			courseActionImpl.responseStream(response, mapper.writeValueAsString(resultMap));
		} catch (Exception e) {
			resultMap.put("result", "fail");
			resultMap.put("failMsg", "评价实验出现异常");
			e.printStackTrace();
			logger.error("评价实验出现异常assessTest", e);
			try {
				courseActionImpl.responseStream(response, mapper.writeValueAsString(resultMap));
			} catch (JsonProcessingException e1) {
				e1.printStackTrace();
			}
		}
	}

	/**
	 * @description    实验管理 or 作业管理  学生提交试验报告or作业
	 * @param request
	 * @param response
	 * @param jsonStr  课程id，章节id chapterId chapterNum，学生号，作业or实验报告的json代码mapList[{"questionId":1,"ansquesContent":""}],
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/uploadTest", method = RequestMethod.POST)
	public void  uploadTest (HttpServletResponse response, HttpServletRequest request, String jsonStr)   {

		//转换json格式工具
		ObjectMapper mapper = new ObjectMapper();
		//存放结果值
		Map<String,Object> resultMap = new HashMap<String,Object>();
		//日志信息
		Logger logger = Logger.getLogger(HomeworkTestAction.class.getName());
		try {
			//获取参数值
			Map<String,Object> paramMap = mapper.readValue(jsonStr, resultMap.getClass());
			//1026如果教师已经批阅了作业信息 true，就返回失败信息
			if(homeworkTestActionImpl.uploadWordMark(request, Long.parseLong(paramMap.get("courseId").toString()), Long.parseLong(paramMap.get("chapterNum").toString()), Long.parseLong(paramMap.get("taskType").toString()))){
				resultMap.put("result","fail");
				resultMap.put("failMsg","已经审核不可在提交");
				courseActionImpl.responseStream(response, mapper.writeValueAsString(resultMap));
				return;
			}
			//添加试验or作业信息
			SessionValues session = new SessionValues();
			Map<String, Object> sessionValues = session.getSessionValues(new String[]{"stuorteaId","roleId"}, request, "userMsg");
			paramMap.put("stuorteaId", sessionValues.get("stuorteaId"));
			resultMap = homeworkTestActionImpl.addTask(paramMap,request);
			boolean addResult = (boolean) resultMap.get("result");
			if(addResult){
				addResult = homeworkTestActionImpl.saveStuTestPracticeUse(paramMap);
			}
			String resultMark = (addResult) ? "success" : "fail";
			if(resultMark.equals("fail")){
				resultMap.put("failMsg", "实验报告内容长度超限，请精简内容缩短长度");
			}else{
				resultMap.put("failMsg", "");
			}
			resultMap.put("result", resultMark);
			courseActionImpl.responseStream(response, mapper.writeValueAsString(resultMap));
		} catch (Exception e) {
			resultMap.put("result","fail");
			resultMap.put("failMsg","提交试验or作业出现异常");
			e.printStackTrace();
			logger.error("提交试验or作业出现异常uploadTest", e);
			try {
				courseActionImpl.responseStream(response, mapper.writeValueAsString(resultMap));
			} catch (JsonProcessingException e1) {
				e1.printStackTrace();
			}
		}
	}


	/**
	 * 3.0 学生上传实验笔记,还有修改实验笔记的。
	 * @description
	 * @param request ，课程id，章节数，html信息
	 * @param response
	 * @return 成功失败标识
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/uploadNote", method = RequestMethod.POST)
	public void  uploadNote (HttpServletResponse response, HttpServletRequest request, String jsonStr)   {

		//转换json格式工具
		ObjectMapper mapper = new ObjectMapper();
		//存放结果值
		Map<String,Object> resultMap = new HashMap<String,Object>();
		//日志信息
		Logger logger = Logger.getLogger(HomeworkTestAction.class.getName());
		try {
			//获取参数值
			Map<String,Object> paramMap = mapper.readValue(jsonStr, resultMap.getClass());
			//保存笔记信息
			Map<String, Object> saveMap = homeworkTestActionImpl.saveNote(paramMap, request);
			String saveResult = ((Boolean)saveMap.get("result")) ? "success" : "fail";
			resultMap.put("result", saveResult);
			courseActionImpl.responseStream(response, mapper.writeValueAsString(resultMap));
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("学生上传实验笔记异常uploadNote", e);
			courseActionImpl.responseStream(response, "{\"result\":\"error\"}");
		}
	}

	/** @description 获取某个学生某课某章节的具体实验信息
	 * @param jsonStr 学号 课程id  第几章节
	 */
	@RequestMapping(value = "/getMyTestDetail", method = RequestMethod.POST)
	public void  getMyTestDetail (HttpServletResponse response ,HttpServletRequest request, String jsonStr)   {
		//通过学号课程号，第几章节获取实验信息
		homeworkTestActionImpl.getMyTestDetail(jsonStr, response,request);
	}

	/** @description 获取某个学生某课某章节的具体作业信息
	 * @param jsonStr 学号 课程id  第几章节
	 */
	@RequestMapping(value = "/getMyHomeworkDetail", method = RequestMethod.POST)
	public void  getMyHomeworkDetail (HttpServletResponse response ,HttpServletRequest request, String jsonStr)   {
		//通过学号课程号，第几章节获取实验信息
		homeworkTestActionImpl.getMyHomeworkDetail(jsonStr, response,request);
	}

	/**
	 * @description 学生保存实验报告信息提交
	 * */
	@RequestMapping(value = "/saveStuTestPractice", method = RequestMethod.POST)
	public void  saveStuTestPractice (HttpServletResponse response , String jsonStr, HttpServletRequest request)   {
		//保存学生的实验信息
		homeworkTestActionImpl.saveStuTestPractice(jsonStr, response, request);
	}

	/**
	 * @description 学生保存作业信息提交
	 * */
	@RequestMapping(value = "/saveStuHomePractice", method = RequestMethod.POST)
	public void  saveStuHomePractice (HttpServletResponse response , String jsonStr, HttpServletRequest request)   {
		//保存学生的作业信息
		homeworkTestActionImpl.saveStuHomePractice(jsonStr, response, request);
	}

	/**
	 * @description  批量下作业、实验报告、试卷等信息
	 * @param request  jsonStr ={"stuorteaId":"0005","downloadType":下载类型：1作业，2实验报告，3试卷}
	 * @param response
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/downloadCourseWorkFile", method = RequestMethod.POST)
	public void downloadCourseWorkFile(String jsonStr, HttpServletRequest request, HttpServletResponse response) {
		homeworkTestActionImpl.downloadCourseWorkFile(jsonStr, request, response);
	}

}